$(document).ready(function(){
	
	var _deleteButton = $("#deleteButton");
	var _selectAll = $("#selectAll");
	var _pageNumber = $("#pageNumber");
	var _listForm = $("#listForm");
	var _delOnes = $("a[type='delOne']");
	
	//批量删除
	_deleteButton.click(function(){
		var _checkIds = $("#listTable input[name='ids']:enabled:checked");
		var　idsStr = _checkIds.serialize();
		if(idsStr==null||idsStr==""){
			alert("请选择您要删除的数据!");
		}else{
			if(confirm("确定要删除选中的数据吗？")){
				location.href = "delete.jhtml?"+idsStr;
			}
		}
	});
	
	//单个删除
	_delOnes.click(function(){
		var idName = $(this).attr("idName");
		var idVal = $(this).attr("idVal");
		if(idVal==null||idVal==""){
			alert("必需参数错误!");
			return;
		}
		if(idName==null||idName==""){
			idName = "com.project.common.web.utils.id";
		}
		if(confirm("确定要删除此信息吗?")){
			location.href = "delete.jhtml?"+idName+"="+idVal;
		}
	});
	
	//全选
	_selectAll.click(function(){
		$("input[name='ids']:enabled").prop("checked",$(this).prop("checked"));
	});
	
	//页码输入
	_pageNumber.keypress(function(event){
		var key = event.keyCode?event.keyCode:event.which;
		if(key==13&&$(this).val().length>0||(key>=48&&key<=57)){
			return true;
		}else{
			return false;
		}
	});
	
	//表单提交
	_listForm.submit(function(){
		if (!/^\d*[1-9]\d*$/.test(_pageNumber.val())) {
			_pageNumber.val("1");
		}
	});
	
	//页码
	$.pageSkip = function(pu){
		_pageNumber.val(pu);
		_listForm.submit();
		return false;
	}
	
	// 列表查询
	if (location.search != "") {
		addCookie("listQuery", location.search);
	} else {
		removeCookie("listQuery");
	}
});

/**
 * 清空列表页面表单
 * f form选择器
 */
function clearFormForList(f){
	$(f).find(':input').not(':button, :submit, :reset').each(function(){
		var _this = $(this);
		if(!_this.prop("disabled")){
			if(_this.attr("type")=="hidden"){
				if(_this.attr("clearVal")==true){
					_this.val('');
				}
			}else{
				if(_this.attr("clearVal")!=false){
					_this.val('').prop("checked",false).prop("selected",false);
				}
			}
		}
	});
}